Ext.onReady(function(){
	
	   var fromPanelInfo = Ext.create('Ext.form.FormPanel',{
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
	       title:'房产信息',
		   items:[{
				xtype : "container",
				layout : "hbox",
				items : [ {
					   xtype:'displayfield',
			    	   fieldLabel:'房号',
			    	   name:'combinedName'
			    	   
				}, {
					 xtype:'displayfield',
			    	 fieldLabel:'房源状态',
			    	 name:'roomStatus'
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'建筑面积',
			    	 name:'buildingArea'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'套内面积',
			    	 name:'innerArea'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'分摊面积',
			    	 name:'sharingArea'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'计价面积',
			    	 name:'buildingArea'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'拆前单价',
			    	 name:'unitPrice'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'拆前总价',
			    	 name:'totalPrice'
				} ]
			}]
		   
	   });
	   
	   
	   
	   
	 
	   
	   var sellInfo = Ext.create('Ext.form.FormPanel',{
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
	       title:'销控信息',
		   items:[{
				xtype : "container",
				layout : "hbox",
				items : [ {
					   xtype:'displayfield',
			    	   fieldLabel:'有效日期',
			    	   id:'dateTime'
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'保留原因',
			    	 name:'reason'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'经办人',
			    	 name:'agentCN'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'销控日期',
			    	 id:'controlDate'
				} ]
			}]
		   
	   });
	   
	   var sellRemark = Ext.create('Ext.form.FormPanel',{
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
	       title:'撤销销控',
	       id:'chexiao',
	       hidden:true,
		   items:[{
				xtype : "container",
				layout : "hbox",
				items : [ {
					   xtype:'displayfield',
			    	   fieldLabel:'撤销原因',
			    	   id:'remark'
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'撤销人',
			    	 name:'updateUser'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'撤销日期',
			    	 id:'updateDate'
				} ]
			}]
		   
	   });
		
	   var fromPanel =  Ext.create('Ext.form.FormPanel',{
	       renderTo:Ext.getBody(),
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
		   	defaultType : 'textfield',
			defaults : {
				anchor : '100%',
			},
			fieldDefaults : {
				flex : 1
			},
	       items:[fromPanelInfo,sellInfo,sellRemark],
	       dockedItems: [{
	            xtype: 'toolbar',
	            dock: 'bottom',
	            ui: 'footer',
	            layout: {
	                pack: 'center'
	            },
	            items: [{
	                minWidth: 80,
	                text: '撤销销控',
	                id:'check_button',
	                hidden:marketingSellControlCancel,
	                handler:function(){
	                	 var window = createWindow();
	                }
	            },{
	                minWidth: 80,
	                text: '返回',
	                handler:function(){
	                	if(returnUrl==''){
	                		location.href=jypath + "/marketing/room/index?menu="+menu;
	                	}else{
	                		location.href=jypath+returnUrl;
	                	}
	                }
	            }]
	        }
	        ]
	       
	       });
	   
	   fromPanel.getForm().load({
			url:jypath+'/marketing/sellControl/resultSellDetail',
			params:{'id':id},
			success:function(form, action){
				var obj = action.result.data;
				hideButton(obj);
				Ext.getCmp("controlDate").setValue(Ext.Date.format(new Date(obj.controlDate),'Y-m-d H:i:s'));
				var start = Ext.Date.format(new Date(obj.startValidity),'Y-m-d');
				var end = Ext.Date.format(new Date(obj.endValidity),'Y-m-d');
				Ext.getCmp("dateTime").setValue(start+"~"+end);
				
			},   
			failure: function(form, action) {
		        Ext.Msg.alert("加载失败", action.result.errorMessage);
		    }

		});
	   
	   function hideButton(obj){
		   //已解除保留，隐藏按钮
		   if(obj.controlType == 1){
			   var date = Ext.Date.format(new Date(obj.updateDate),'Y-m-d');
			   Ext.getCmp("updateDate").setValue(date);
			   Ext.getCmp("chexiao").show();
		   }else{
			   //显示
			   if(marketingSellControlCancel==false){
				   Ext.getCmp("check_button").show();
			   }
			  
		   }
	   }
	   
	   /**
		 * 撤销销控
		 * @param title
		 * @returns
		 */
		function createWindow(){
			return Ext.create('Ext.Window', {
		        title: '撤销销控',
		        width: 450,
		        height: 200,
		        plain: true,
		        modal: true,
		        headerPosition: 'top',
		        items: [sellfromPanel]
		    }).show();
		} 
		
		var sellfromPanel = new Ext.form.FormPanel({
			region : 'north',
			frame : true,
			items:[
			       {
			    	   xtype:'textarea',
			    	   fieldLabel:'撤销原因',
			    	   labelAlign:'right',
			    	   labelWidth:60,
			    	   width:420,
			    	   height:120,
				       id:'text'	   
			       }
			 ],
			 dockedItems: [{
		            xtype: 'toolbar',
		            dock: 'bottom',
		            ui: 'footer',
		            layout: {
		                pack: 'center'
		            },
		            items: [{
		                minWidth: 80,
		                text: '保存',
		                id:'save_button',
		                handler:function(){
		                	 Ext.MessageBox.confirm("提示","是否确定撤销销控?",function(btn,txt){
		                		 if(btn=="yes"){
		                			 	var remark = Ext.getCmp("text").getValue();
		                			 	if(remark == ""){
		                			 		Ext.MessageBox.alert("系统提示","请填写撤销原因");
		                			 		return false;
		                			 	}
		                			 	if(remark.length > 255){
		                			 		Ext.MessageBox.alert("系统提示","撤销原因超出字数限制");
		                			 		return false;
		                			 	}
		                				Ext.Ajax.request({
		                					url:jypath+'/marketing/sellControl/sellControlRevoke',
		                		    		params:{
		                		    			"id":id,
		                		    			"remark":remark
		                		    		},
		                		    		callback: function (options, success, response) {
		                		    			 var obj = JSON.parse(response.responseText);
		                		    			 if(obj.res=="1"){
		                		    				 Ext.MessageBox.alert("系统提示","撤销成功");
		                		    				 //Ext.getCmp("check_button").setVisible(false);
		                		    				 location.reload(true);
		                		    			 }
		                		    		}
		                				});
		                		 }
		                	 });
		                }
		            }]
		      }]
		});
		
	
});